{% extends "djangobmf/base.html" %}

{% load i18n %}

{% block title %}{% trans "Notifications" %}{% endblock %}

{% block full_content %}
<div class="row">
    <div class="col-lg-9 col-sm-8">
        <ul class="nav nav-tabs">
            {% if glob_settings %}
            <li{% if datafilter == "unread" %} class="active"{% endif %}><a href="{% url 'djangobmf:notification' ct=selected_ct filter="unread" %}">{% trans "Unread" %}</a></li>
            <li{% if datafilter == "active" %} class="active"{% endif %}><a href="{% url 'djangobmf:notification' ct=selected_ct filter="active" %}">{% trans "Active" %}</a></li>
            <li{% if datafilter == "all" %} class="active"{% endif %}><a href="{% url 'djangobmf:notification' ct=selected_ct filter="all" %}">{% trans "All" %}</a></li>
            {% else %}
            <li{% if datafilter == "unread" %} class="active"{% endif %}><a href="{% url 'djangobmf:notification' filter="unread" %}">{% trans "Unread" %}</a></li>
            <li{% if datafilter == "active" %} class="active"{% endif %}><a href="{% url 'djangobmf:notification' filter="active" %}">{% trans "Active" %}</a></li>
            <li{% if datafilter == "all" %} class="active"{% endif %}><a href="{% url 'djangobmf:notification' filter="all" %}">{% trans "All" %}</a></li>
            {% endif %}
        </ul>
        <p class="text-right" style="padding: 0.5em 0">
            {% if glob_settings %}
                {% trans "Default settings" %}:
                {% url "djangobmf:api-notification" model=model_name app=app_label as url %}
                <a href="{{ url }}" class="btn" bmf-notification="new_entry" data-enabled="{{ glob_settings.new_entry|yesno:"true,false" }}"></a>

                {% if has_detectchanges %}
                    <a href="{{ url }}" class="btn" bmf-notification="detectchanges" data-enabled="{{ glob_settings.detectchanges|yesno:"true,false" }}"></a>
                {% endif %}

                {% if has_workflow %}
                    <a href="{{ url }}" class="btn" bmf-notification="workflow" data-enabled="{{ glob_settings.workflow|yesno:"true,false" }}"></a>
                {% endif %}

                {% if has_comments %}
                    <a href="{{ url }}" class="btn" bmf-notification="comments" data-enabled="{{ glob_settings.comments|yesno:"true,false" }}"></a>
                {% endif %}

                {% if has_files %}
                    <a href="{{ url }}" class="btn" bmf-notification="files" data-enabled="{{ glob_settings.files|yesno:"true,false" }}"></a>
                {% endif %}
            {% else %}
            <button class="btn disabled" href="#">{% trans "Select a category to edit the default settings" %}</button>
            {% endif %}
        </p>
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>{% trans "Notifications" %}</th>
                    <th style="width: 150px;"></th>
                </tr>
            </thead>
            <tbody>
                {% for item in object_list %}
                <tr{% if not item.is_active %} class="text-muted"{% endif %}>
                    <td>
                        <a href="{{ item.watch_object.bmfmodule_detail }}">{{ item.watch_object }}</a>
                        {% if item.unread %}<span class="label label-primary">new</span>{% endif %}
                        <br><span><small>
                            {% if not glob_settings %}[{{ item.watch_ct }}]{% endif %}
                            {{ item.modified|date:"SHORT_DATETIME_FORMAT" }}
                        </small></span>
                    </td>
                    <td class="text-right">
                        {% url "djangobmf:api-notification" model=model_name app=app_label pk=item.watch_id as url %}

                        {% if has_detectchanges %}
                            <a href="{{ url }}" class="btn btn-sm" bmf-notification="detectchanges" data-enabled="{{ item.detectchanges|yesno:"true,false" }}"></a>
                        {% endif %}

                        {% if has_workflow %}
                            <a href="{{ url }}" class="btn btn-sm" bmf-notification="workflow" data-enabled="{{ item.workflow|yesno:"true,false" }}"></a>
                        {% endif %}

                        {% if has_comments %}
                            <a href="{{ url }}" class="btn btn-sm" bmf-notification="comments" data-enabled="{{ item.comments|yesno:"true,false" }}"></a>
                        {% endif %}

                        {% if has_files %}
                            <a href="{{ url }}" class="btn btn-sm" bmf-notification="files" data-enabled="{{ item.files|yesno:"true,false" }}"></a>
                        {% endif %}

                    </td>
                </tr>
                {% empty %}
                <tr>
                    <td colspan="2"><em>{% trans "You dont have notifications" %}</em></td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% if is_paginated %}
        <ul class="pager">
            {% if page_obj.has_previous %}
            <li class="previous"><a href="?page={{ page_obj.previous_page_number }}">{% trans "Previous" %}</a></li>
            {% endif %}
            {% if page_obj.has_next %}
            <li class="next"><a href="?page={{ page_obj.next_page_number }}">{% trans "Next" %}</a></li>
            {% endif %}
        </ul>
        </div>
        {% endif %}
    </div>
    <div class="col-lg-3 col-sm-4">
        <ul class="nav nav-pills nav-stacked">
            <li{% if not selected_ct %} class="active"{% endif %}>
                <a href="{% url 'djangobmf:notification' filter=datafilter %}">
                    {% if unread > 0 %}<span class="badge pull-right">{{ unread }}</span>{% endif %}
                    {% trans "All" %}
                </a>
            </li>
            {% for item in navigation|dictsort:"name" %}
            {% if item.visible or item.count %}
            <li{% if item.ct == selected_ct %} class="active"{% endif %}>
                <a href="{% url 'djangobmf:notification' ct=item.ct filter=datafilter %}">
                    {% if item.count %}<span class="badge pull-right">{{ item.count }}</span>{% endif %}
                    {{ item.name }}
                </a>
            </li>
            {% endif %}
            {% endfor %}
        </ul>
    </div>
</div>
{% endblock %}
